﻿using System;
using System.Web.UI.WebControls;
using BLL;
using BLL.Access;
using System.Data;
using DevExpress.Web;

namespace Web.Pages.YongShui._13.LAIHANGL
{
    public partial class LaiHanLCPZ : BasePage
    {
        #region 属性
        
        #endregion

        #region 变量
        
        #endregion
        /// <summary>
        /// 数据库访问
        /// </summary>
        SpHelper _sphelper = new SpHelper();

        /// <summary>
        /// 来函类型审批流程配置
        /// </summary>
        YS_LH_LIUCHENGPZProcess bllLC = new YS_LH_LIUCHENGPZProcess();

        
        #region 事件       
        /// <summary>
        /// 页面首次加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
                BindGv();
            }
        }
        /// <summary>
        /// 来函类型改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cmLaiHanLX_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindGv();
        }
        /// <summary>
        /// 去除已有审批流程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnLeft_Click(object sender, EventArgs e)
        {
            ToLeft();
            BindGv();
        }
        /// <summary>
        /// 添加新的审批流程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnRight_Click(object sender, EventArgs e)
        {
            ToRight();
            BindGv();
        }
        #endregion


        #region 方法
        /// <summary>
        /// 初始化绑定控件
        /// </summary>
        private void InitControl()
        {
            //绑定来函类型
            DataSet ds = _sphelper.P_YS_LH_LAIHANLX(BusinessTool.WType);
            cmLaiHanLX.DataSource = ds;
            cmLaiHanLX.TextField = "S_LAIHANLXMC";
            cmLaiHanLX.ValueField = "I_LAIHANH";
            cmLaiHanLX.DataBind();
            cmLaiHanLX.SelectedIndex = 0;
        }
        /// <summary>
        /// 绑定gvlist数据
        /// </summary>
        private void BindGv()
        {
            string leftwhere = " and i_shenpilcbh not in (select b.i_liuchengbh from ys_lh_liuchengpz b where b.i_laihanlx=" + cmLaiHanLX.Value + " and b.I_JLZT=0)";
            DataSet leftDs = _sphelper.P_YS_LH_SHENPILCCXBYWHERE(0,leftwhere,null,null,null);

            string rightwhere = "  and i_shenpilcbh  in (select b.i_liuchengbh from ys_lh_liuchengpz b where b.i_laihanlx=" + cmLaiHanLX.Value + " and b.I_JLZT=0)";
            DataSet rightDs = _sphelper.P_YS_LH_SHENPILCCXBYWHERE(0,rightwhere,null,null,null);

            gvLeftList.DataSource = leftDs.Tables[0];
            gvLeftList.DataBind();
            gvRightList.DataSource = rightDs.Tables[0];
            gvRightList.DataBind();
        }
        /// <summary>
        /// 把右侧转移到左侧
        /// </summary>
        private void ToLeft()
        {
            int laihanlx = Convert.ToInt32(cmLaiHanLX.Value);
            for (int i = 0; i < gvRightList.VisibleRowCount; i++)
            {
                ASPxCheckBox ck = (ASPxCheckBox)gvRightList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvRightList.Columns[0], "LCID");
                HiddenField hid = (HiddenField)gvRightList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvRightList.Columns[0], "hid");
                if (ck.Checked)
                {
                    int shenpilcbh = Convert.ToInt32(hid.Value);
                    DataSet ds = _sphelper.P_YS_LH_SHENPILCCXBYWHERE(2, "", laihanlx, shenpilcbh, 0);                   
                }
            }
        }
        /// <summary>
        /// 把左侧流程记录添加到右侧
        /// </summary>
        private void ToRight()
        {
            int? laihanlx = Convert.ToInt32(cmLaiHanLX.Value);
            
            for (int i = 0; i < gvLeftList.VisibleRowCount; i++)
            {
                ASPxCheckBox ck = (ASPxCheckBox)gvLeftList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLeftList.Columns[0], "LCID");
                HiddenField hid = (HiddenField)gvLeftList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLeftList.Columns[0], "hid");
                if (ck.Checked)
                {
                    int? shenpilcbh = Convert.ToInt32(hid.Value);
                    DataSet ds = _sphelper.P_YS_LH_SHENPILCCXBYWHERE(1, "", laihanlx, shenpilcbh,0 );
                    
                   
                }
            }
        }
        #endregion

        
    }
}